'use strict';
const dayjs = require("dayjs");
module.exports = app => {
    const { STRING, INTEGER, TINYINT, DATE } = app.Sequelize;
    const Model = app.model.define(
        'matout',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            /**
             * `company` int DEFAULT NULL,
             *   `store` int DEFAULT NULL COMMENT '仓库',
             *   `mat` int DEFAULT NULL COMMENT '物料',
             *   `outNum` double DEFAULT NULL COMMENT '出库量',
             *   `outTime` date DEFAULT NULL COMMENT '出库时间',
             *   `responser` varchar(20) DEFAULT NULL COMMENT '负责人',
             *   `remark` varchar(200) DEFAULT NULL COMMENT '备注',
             *   `version` int DEFAULT '1',
             *   `is_deleted` tinyint(1) DEFAULT '0',
             */
            company: INTEGER,
            store: INTEGER,
            mat: INTEGER,
            outnum: STRING(50),
            outtime: {
                type:DATE,
                get() {
                    return dayjs(this.getDataValue('outtime')).format('YYYY-MM-DD');
                }
            },
            responser: STRING(20),
            remark: STRING(200),
            version: INTEGER,
            is_deleted: TINYINT(1),
        },
        {
            tableName: 'matout',
            timestamps: true, // 启用时间戳(createdAt, updatedAt)
            updatedAt: false, // 不想要 updatedAt
            createdAt: false, // 想要  createdAt 但是希望名称叫做 created_at
        }
    );
    Model.associate = function() {
        app.model.Matout.belongsTo(app.model.CompanyModel, { foreignKey: 'company', targetKey: 'id' });
        app.model.Matout.belongsTo(app.model.MatModel, { foreignKey: 'mat', targetKey: 'id' });
    }
    return Model
};
